package org.yaac.server.egql.evaluator.function;

import static com.google.common.collect.Lists.newLinkedList;

import java.util.List;

import org.yaac.server.egql.evaluator.EvaluationResult;
import org.yaac.server.egql.evaluator.Evaluator;
import org.yaac.server.egql.exception.EGQLException;
import org.yaac.server.egql.processor.ProcessData.ProcessDataRecord;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class ListFunction extends Function {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void validate() throws EGQLException {
		// can be any no of ops  
	}

	@Override
	public EvaluationResult evaluate(ProcessDataRecord record) {
		List<Object> payloadList = newLinkedList();
		List<EvaluationResult> resultList = newLinkedList();
		
		for (Evaluator e : this.ops) {
			EvaluationResult r = e.evaluate(record);
			
			resultList.add(r);
			payloadList.add(r.getPayload());
		}
		
		return new EvaluationResult(payloadList, resultList);
	}
}
